import { ObjCreate } from "../../common/ObjCreate";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../../extend/language/Language";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { ESpringInteractType } from "../../../../../Message/Game/ESpringInteractType";
import { SecTimer } from "../../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../../com/gengine/core/frame/TimerType";
import { ClockManager } from "../../../manager/ClockManager";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { MsgManager } from "../../../manager/MsgManager";
import { Cache } from "../../../cache/Cache";
import { PulseSharedObject } from "../../player/PulseSharedObject";
import { TodayNoTipsConst } from "../../../../component/gconst/TodayNoTipsConst";
import { ThingUtil } from "../../../scene/layer/utils/ThingUtil";
import { AIManager } from "../../../scene/ai/AIManager";
import { AIType } from "../../../scene/ai/AIType";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
import { GLabel } from "../../../../../com/mui/controls/GLabel";
type int = number;
//class SpaInteractButton
    
    export  class SpaInteractButton /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.createChildren();
            return;
        }

        public set lastTime(arg1: number)
        {
            this._lastTime = arg1;
            return;
        }

        public get lastTime(): number
        {
            return this._lastTime;
        }

        /* internal  */createChildren(): void
        {
            this._btn = ObjCreate.createGLoadedButton(ResFileConst.spaInteractBtn, 0, 0, 57, 57, this);
            this._btn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            this._bmLabel = new Object /* flash.display.Bitmap */();
            this.addChild(this._bmLabel);
            var loc1=new GTextFormat();
            loc1.align = flash.text.TextFormatAlign.CENTER;
            loc1.color = 15530500;
            loc1.size = 14;
            loc1.bold = false;
            loc1.letterSpacing = 2;
            this._label = ObjCreate.createLabel("", 0, 32, 57, 20, flash.text.TextFormatAlign.CENTER, this, true);
            this._label.setStyle("textFormat", loc1);
            this._label.mouseEnabled = false;
            this._label.mouseChildren = false;
            this._countDownLabel = ObjCreate.createLabel("", -10, 58, 77, 20, flash.text.TextFormatAlign.CENTER, this, true);
            this._countDownLabel.mouseEnabled = false;
            this._countDownLabel.mouseChildren = false;
            return;
        }

        public set type(arg1: int)
        {
            var loc1=arg1;
            switch (loc1) 
            {
                case -1:
                {
                    this._btn.toolTipData = HTMLUtil.addColor(Language.getString(60703), "#FFFFFF");
                    this._bmLabel.x = 7;
                    this._bmLabel.y = 7;
                    this._bmLabel.bitmapData = GlobalClass.getBitmapData(ImagesConst.leaveSpaLabel);
                    break;
                }
                case ESpringInteractType._ESpringInteractTypeRubback:
                {
                    this._btn.toolTipData = HTMLUtil.addColor(Language.getString(60702), "#FFFFFF");
                    this._bmLabel.x = 6;
                    this._bmLabel.y = 9;
                    this._bmLabel.bitmapData = GlobalClass.getBitmapData(ImagesConst.rubBackLabel);
                    break;
                }
                case ESpringInteractType._ESpringInteractTypeRubdown:
                {
                    this._btn.toolTipData = HTMLUtil.addColor(Language.getString(60702), "#FFFFFF");
                    this._bmLabel.x = 6;
                    this._bmLabel.y = 9;
                    this._bmLabel.bitmapData = GlobalClass.getBitmapData(ImagesConst.rubDownLabel);
                    break;
                }
                case ESpringInteractType._ESpringInteractTypeSoap:
                {
                    this._btn.toolTipData = HTMLUtil.addColor(Language.getString(60701), "#FFFFFF");
                    this._bmLabel.x = 3;
                    this._bmLabel.y = 9;
                    this._bmLabel.bitmapData = GlobalClass.getBitmapData(ImagesConst.passSoupLabel);
                    break;
                }
            }
            this._type = arg1;
            return;
        }

        public setNumLabel(arg1: int): void
        {
            this._remainTimes = arg1;
            this._label.htmlText = arg1 + Language.getString(60337);
            return;
        }

        public startCountDown(): void
        {
            this._isCdIng = true;
            if (!this._timer) 
            {
                this._timer = new SecTimer(1, 30);
                this._timer.addListener(TimerType.ENTERFRAME, this.onTimerEvent);
                this._timer.addListener(TimerType.COMPLETE, this.onTimerComplete);
            }
            this._timer.reset();
            this._timer.start();
            return;
        }

        /* internal  */onTimerEvent(arg1: SecTimer): void
        {
            this._countDownLabel.htmlText = Language.getString(60338) + arg1.repeatCount;
            return;
        }

        /* internal  */onTimerComplete(arg1: SecTimer): void
        {
            this._isCdIng = false;
            this._countDownLabel.htmlText = "";
            if (this._timer) 
            {
                this._timer.stop();
                this._timer = null;
            }
            return;
        }

        public updateClickTime(): void
        {
            this._lastTime = ClockManager.instance.nowDate.time + 5000;
            return;
        }

        /* internal  */onButtonClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var e: Object /* flash.events.MouseEvent */;

            var loc1;
            e = arg1;
            var loc2=this._type;
            switch (loc2) 
            {
                case -1:
                {
                    Alert.show(Language.getString(60339), Language.getString(69900), Alert.OK | Alert.CANCEL, null, (arg1: int): void
                    {
                        if (arg1 == Alert.OK) 
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.SpaLeaveSpa));
                        }
                        return;
                    })
                    break;
                }
                default:
                {
                    if (this._lastTime > ClockManager.instance.nowDate.time) 
                    {
                        return;
                    }
                    if (this._remainTimes == 0) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(60340));
                        return;
                    }
                    if (this._isCdIng) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(60341));
                        return;
                    }
                    if (this._type == ESpringInteractType._ESpringInteractTypeSoap) 
                    {
                        if (!Cache.instance.spa.hasSoaps()) 
                        {
                            MsgManager.showRollTipsMsg(Language.getString(60342));
                            if (!PulseSharedObject.isTodayNotTips(TodayNoTipsConst.SpaLackSoapTodayNoTips)) 
                            {
                                Dispatcher.dispatchEvent(new DataEvent(EventName.SpaShowLackSoapTipsWin));
                            }
                            return;
                        }
                    }
                    if (ThingUtil.selectEntity) 
                    {
                        Cache.instance.spa.interactType = this._type;
                        AIManager.onAIControl(ThingUtil.selectEntity, AIType.AI_SpaInteract);
                    }
                    else 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(60343));
                    }
                    break;
                }
            }
            return;
        }

        /* internal */ /* var */_type: int;

        /* internal */ /* var */_remainTimes: int;

        /* internal */ /* var */_btn: GLoadedButton;

        /* internal */ /* var */_bmLabel: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_label: GLabel;

        /* internal */ /* var */_countDownLabel: GLabel;

        /* internal */ /* var */_timer: SecTimer;

        /* internal */ /* var */_isCdIng: Boolean;

        /* internal */ /* var */_lastTime: number=0;
    }
